import cv2 as cv
import numpy as np


def hough_circle_detect():
    src_img = cv.imread('../image//ball.png')
    cv.imshow('source image', src_img)
    src_img = cv.medianBlur(src_img, 7)
    gray_img = cv.cvtColor(src_img, cv.COLOR_BGR2GRAY)
    circles = cv.HoughCircles(gray_img, cv.HOUGH_GRADIENT, 2, 120, param1=100, param2=20, minRadius=20, maxRadius=50)
    circles = np.uint16(np.around(circles))
    print("circles:", circles)
    for circle in circles[0, :]:
        print('circle:\r\n', circle)
        cv.circle(src_img, (circle[0], circle[1]), circle[2], (0, 255, 0), 2)
    cv.imshow('gray image', src_img)
    cv.waitKey(0)


def main():
    hough_circle_detect()


if __name__ == '__main__':
    main()

